#include "StaticRole.h"

void StaticRole::parse()
{
	const char* path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("config/Boss.xml");

	xmlDocPtr bossDoc = xmlReadFile(path, "utf-8", XML_PARSER_EOF);
	if(NULL == bossDoc)
		CCLOG("Boss xml parse failed!");

	xmlNodePtr bossRootNode = xmlDocGetRootElement(bossDoc);
	if(NULL == bossRootNode)
		CCLOG("Boss xml root null!");

	xmlNodePtr bossChildNode = bossRootNode->last->last;
	xmlNodePtr curNode = bossChildNode;
	while(NULL != curNode)
	{
		if (curNode->type == XML_COMMENT_NODE)break;
		BossInfo* bossInfo = new BossInfo();
		bossInfo->id = attriToInt(curNode, "id");
		bossInfo->name = attriToChar(curNode,"name");
		bossInfo->icon = attriToChar(curNode,"icon");
		bossInfo->level = attriToInt(curNode,"level");
		bossInfo->life = attriToInt(curNode,"life");
		bossInfo->atk_min = attriToInt(curNode,"atk_min");
		bossInfo->atk_max = attriToInt(curNode,"atk_max");
		bossInfo->def = attriToInt(curNode,"def");
		bossInfo->power = attriToInt(curNode,"power");
		bossInfo->speed = attriToInt(curNode,"speed");
		bossInfo->stamina = attriToInt(curNode,"stamina");
		bossInfoMap[bossInfo->id] = bossInfo;
		curNode = curNode->prev;
	}
	xmlFreeDoc(bossDoc);
}

BossInfo* StaticRole::getBossInfo(int id)
{
	if (bossInfoMap.count(id) == 0)
		return NULL;
	return bossInfoMap[id];
}

RoleInfo* StaticRole::getRoleInfo( int id )
{
	return getBossInfo(id);
}

StaticRole::StaticRole()
{
	parse();
}

StaticRole::~StaticRole()
{

}
